package org.aplikator.client.descriptor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("serial")
public class ViewDTO extends ClientDescriptorBase implements Cloneable {

    private List<PropertyDTO<? extends Serializable>> properties = new ArrayList<PropertyDTO<? extends Serializable>>();

    private String searchString = null;

    private QueryParameter[] queryParameters;

    private FormDTO formDescriptor;

    private PropertyDTO<? extends Serializable> sortProperty = null;

    private EntityDTO entity;

    private int pageSize;

    private boolean sortAscending = true;

    @SuppressWarnings("unused")
    private ViewDTO() {
    }

    public ViewDTO(String id, String localizedName, int pageSize) {
        super(id, localizedName);
        this.pageSize = pageSize;
    }

    public List<PropertyDTO<? extends Serializable>> getProperties() {
        return properties;
    }

    public ViewDTO addProperty(PropertyDTO<? extends Serializable> property) {
        properties.add(property);
        return this;
    }

    public QueryParameter[] getQueryParameters() {
        return queryParameters;
    }

    public void setQueryParameters(QueryParameter[] queryParameters) {
        this.queryParameters = queryParameters;
    }

    public FormDTO getFormDescriptor() {
        return formDescriptor;
    }

    public void setFormDescriptor(FormDTO formDescriptor) {
        this.formDescriptor = formDescriptor;
    }

    public int getPageSize() {
        return pageSize;
    }

    public EntityDTO getEntity() {
        return entity;
    }

    public void setEntity(EntityDTO entity) {
        this.entity = entity;
    }

    public String getSearchString() {
        return searchString;
    }

    public void setSearchString(String searchString) {
        this.searchString = searchString;
    }

    public ViewDTO clone() {
        ViewDTO retval = new ViewDTO(this.getId(), this.getLocalizedName(), this.getPageSize());
        retval.setLocalizedName(this.getLocalizedName());
        retval.formDescriptor = this.formDescriptor;
        retval.entity = this.entity;
        retval.properties = this.properties;
        retval.queryParameters = new QueryParameter[this.queryParameters.length];
        for (int i = 0; i < retval.queryParameters.length; i++) {
            retval.queryParameters[i] = new QueryParameter(this.queryParameters[i].getName());
        }
        retval.searchString = this.searchString;
        retval.setSortProperty(this.getSortProperty());
        retval.setSortAscending(this.isSortAscending());
        return retval;
    }

    public PropertyDTO<? extends Serializable> getSortProperty() {
        return sortProperty;
    }

    public void setSortProperty(PropertyDTO<? extends Serializable> sortProperty) {
        this.sortProperty = sortProperty;
    }

    public boolean isSortAscending() {
        return sortAscending;
    }

    public void setSortAscending(boolean sortAscending) {
        this.sortAscending = sortAscending;
    }

}
